package xin.yangshuai.swagger2.controller;

import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import xin.yangshuai.swagger2.support.User;

/**
 * @ClassName SwaggerController
 * @Description TODO
 * @Author shuai
 * @Date 2018/9/18 11:16
 * @Version 1.0
 **/
@Api("测试类")
@Controller
@RequestMapping("swagger")
public class SwaggerController {
    @ApiOperation(value = "测试方法", httpMethod = "GET")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "Successful — 请求已完成"),
            @ApiResponse(code = 400, message = "请求中有语法问题，或不能满足请求"),
            @ApiResponse(code = 401, message = "未授权客户机访问数据"),
            @ApiResponse(code = 403, message = "资源不可用"),
            @ApiResponse(code = 404, message = "服务器找不到给定的资源；文档不存在"),
            @ApiResponse(code = 500, message = "服务器不能完成请求")}
    )
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    @ResponseBody
    public String hello() {
        return "hello word!!!";
    }

    @ApiOperation(value = "获取用户信息", notes = "根据userId获取用户", httpMethod = "GET", response = User.class)
    @ResponseBody
    @RequestMapping(value = "/getUser", method = RequestMethod.GET)
    public Object getUser(@ApiParam(required = true, value = "用户ID", name = "userId") @RequestParam(value = "userId") Integer userId
            , @ApiParam(required = true, value = "用户ID", name = "userName") @RequestParam(value = "userName") String userName) {
        User user = new User();
        user.setId(userId);
        user.setName(userName);
        return user;
    }
}